{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.utils.data as Data\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "batch_size = 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.]),\n",
       " tensor([10.,  9.,  8.,  7.,  6.,  5.,  4.,  3.,  2.,  1.]))"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = torch.linspace(1, 10, 10) # 1到10， 10个\n",
    "y = torch.linspace(10, 1, 10) # 10到1， 10个\n",
    "x,y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "torch_dataset = Data.TensorDataset(x, y)\n",
    "loader = Data.DataLoader(dataset=torch_dataset,\n",
    "                        batch_size=batch_size,\n",
    "                        shuffle=False,)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 0 [1. 2. 3. 4. 5. 6. 7. 8.] [10.  9.  8.  7.  6.  5.  4.  3.]\n",
      "0 1 [ 9. 10.] [2. 1.]\n",
      "1 0 [1. 2. 3. 4. 5. 6. 7. 8.] [10.  9.  8.  7.  6.  5.  4.  3.]\n",
      "1 1 [ 9. 10.] [2. 1.]\n",
      "2 0 [1. 2. 3. 4. 5. 6. 7. 8.] [10.  9.  8.  7.  6.  5.  4.  3.]\n",
      "2 1 [ 9. 10.] [2. 1.]\n"
     ]
    }
   ],
   "source": [
    "for epoch in range(3):\n",
    "    for step, (batch_x, batch_y) in enumerate(loader):\n",
    "        print(epoch,\n",
    "        step,\n",
    "        batch_x.numpy(),\n",
    "        batch_y.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.7 64-bit",
   "language": "python",
   "name": "python37764bita7c2719225b84763be647c75e40e67b2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
